//我们保证独立完成了整个程序从分析、设计到编码的所有工作。
//本段代码编写<202131773419-况思鹏>

import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;

public class BackGround {
//    当前场景要显示的图像
    private BufferedImage bgImage = null;
    //    记录当前是第几个场景
    private  int sort;
//    判断是否为最后一个场景
    private int flag;
    //用于存放我们所有障碍物
    private List<Obstacle>obstacleList=new ArrayList<>();
//    用于存放我们所有的敌人
    private List<Enemy>enemyList=new ArrayList<>();
//    用于显示旗杆
    private BufferedImage gan=null;
//    用于显示城堡
    private BufferedImage tower = null;
//    判断马里奥是否到达旗杆位置
    private boolean isReach=false;
//    判断旗子是否落地
    private boolean isBase=false;
    public BackGround(){

    }
    public BackGround(int sort, int flag){
        this.sort = sort;
        this.flag = flag;

        if(flag == 3){
            bgImage = StaticValue.bg3;
        }else if(flag == 2){
            bgImage = StaticValue.bg2;
        }else if(flag == 1){
            bgImage = StaticValue.bg;
        }else{
            bgImage = StaticValue.bg4;
        }
  //        判断是否是第一关
        if(sort==1) {
//            绘制第一关的地面， 上地面type=1，下地面type=2
            for (int i = 0; i < 27; i++) {
                obstacleList.add(new Obstacle(i * 30, 420, 1, this));
            }
            for (int j = 0; j <= 120; j += 30) {
                for (int i = 0; i < 27; i++) {
                    obstacleList.add(new Obstacle(i * 30, 570 - j, 2, this));
                }
            }
//            绘制砖块A
            for (int i = 120; i <= 150; i += 30) {
                obstacleList.add(new Obstacle(i, 300, 7, this));
            }
//            绘制砖块B-F
            for (int i = 300; i <= 570; i += 30) {
                if (i == 360 || i == 390 || i == 480 || i == 510 || i == 540) {
                    obstacleList.add(new Obstacle(i, 300, 7, this));
                } else {
                    obstacleList.add(new Obstacle(i, 300, 0, this));
                }
            }
//        绘制砖块G
            for (int i = 420; i <= 450; i += 30) {
                obstacleList.add(new Obstacle(i, 240, 7, this));
            }
//        绘制水管
            for (int i = 360; i <= 600; i += 25) {
                if (i == 360) {
                    obstacleList.add(new Obstacle(620, i, 3, this));
                    obstacleList.add(new Obstacle(645, i, 4, this));
                } else {
                    obstacleList.add(new Obstacle(620, i, 5, this));
                    obstacleList.add(new Obstacle(645, i, 6, this));
                }
            }
//            绘制第一关的蘑菇敌人
            enemyList.add(new Enemy(580,385,true,1,this));
//            绘制第一关的食人花敌人
            enemyList.add(new Enemy(635,420,true,2,328,428,this));
            //绘制第一关蘑菇敌人
            enemyList.add(new Enemy(670,385,true,1,this));
            enemyList.add(new Enemy(635,20,true,5,this,800,true));

        }


//        判断是否为第二关
        if(sort==2){
            //            绘制第二关的地面，上地面type=1，下地面type=2
            for(int i=0;i<27;i++){
                obstacleList.add(new Obstacle(i*30,420,1,this));
            }
            for(int j=0;j<=120;j+=30){
                for(int i=0;i<27;i++){
                    obstacleList.add(new Obstacle(i*30,570-j,2,this));
                }
            }
//            绘制第一个水管
            for (int i = 360; i <= 600; i += 25) {
                if (i == 360) {
                    obstacleList.add(new Obstacle(60, i, 3, this));
                    obstacleList.add(new Obstacle(85, i, 4, this));
                } else {
                    obstacleList.add(new Obstacle(60, i, 5, this));
                    obstacleList.add(new Obstacle(85, i, 6, this));
                }
            }
//            绘制第二个水管
            for (int i = 330; i <= 600; i += 25) {
                if (i == 330) {
                    obstacleList.add(new Obstacle(620, i, 3, this));
                    obstacleList.add(new Obstacle(645, i, 4, this));
                } else {
                    obstacleList.add(new Obstacle(620, i, 5, this));
                    obstacleList.add(new Obstacle(645, i, 6, this));
                }
            }
//            绘制砖块C
            obstacleList.add(new Obstacle(300,330,0,this));
//            绘制砖块B、E、G
            for (int i =270;i<=330;i+=30){
                if(i==270||i==330){
                    obstacleList.add(new Obstacle(i,360,0,this));
                }else {
                    obstacleList.add(new Obstacle(i,360,7,this));
                }
            }
//            绘制砖块A、D、F、H、I
            for (int i =240;i<=360;i+=30){
                if (i ==240||i==360){
                    obstacleList.add(new Obstacle(i,390,0,this));
                }else {
                    obstacleList.add(new Obstacle(i,390,7,this));
                }
            }
//            绘制妨碍1砖块
            obstacleList.add(new Obstacle(240,300,0,this));
            //        绘制空1-4砖块
            for (int i =360;i<=540;i+=60){
                obstacleList.add(new Obstacle(i,270,7,this));
            }
            //绘制第二关阻挡方块
            obstacleList.add(new Obstacle(300,240,7,this));
            obstacleList.add(new Obstacle(600,240,7,this));
//            绘制第二关的第一个食人花敌人
            enemyList.add(new Enemy(75,420,true,2,328,418,this));
//            绘制第二关的第二更食人花敌人
            enemyList.add(new Enemy(635,420,true,2,298,388,this));
//            绘制第二关的第一个蘑菇敌人
            enemyList.add(new Enemy(200,385,true,1,this));
//            绘制第二更的第二个蘑菇敌人
            enemyList.add(new Enemy(500,385,true,1,this));
            //绘制第二关的第一个鸟敌人
            enemyList.add(new Enemy(500,240,true,3,this));


        }


        //是否为第三关
        if(sort == 3){
                    //            绘制第三关的地面，上地面type=1，下地面type=2
            for(int i=0;i<3;i++){
                obstacleList.add(new Obstacle(i*30,420,1,this));
            }
            for(int i=24;i<27;i++){
                obstacleList.add(new Obstacle(i*30,420,1,this));
            }
            for(int j=0;j<=120;j+=30){
                for(int i=0;i<3;i++){
                    obstacleList.add(new Obstacle(i*30,570-j,2,this));
                }
                for(int i=24;i<27;i++){
                    obstacleList.add(new Obstacle(i*30,570-j,2,this));
                }
            }
        //左边第一个方块
            obstacleList.add(new Obstacle(120,380,7,this));
            obstacleList.add(new Obstacle(150,380,7,this));
            //左上第一排四个
            for(int i = 210;i <= 300;i += 30){
                obstacleList.add(new Obstacle(i,350,7,this));
            }
            //中间三个
            obstacleList.add(new Obstacle(360,350,7,this));
            obstacleList.add(new Obstacle(420,440,7,this));

            //右上二
            obstacleList.add(new Obstacle(480,320,7,this));
            //右上8
            for(int i = 480;i < 630;i+=30){
                obstacleList.add(new Obstacle(i,350,7,this));
            }
            //右下四
            for(int i = 480; i < 570; i += 30){
                obstacleList.add(new Obstacle(i,440,7,this));
            }
            //右二
            obstacleList.add(new Obstacle(600,500,7,this));
            obstacleList.add(new Obstacle(660,440,7,this));
//阻挡
            obstacleList.add(new Obstacle(580,380,7,this));
            obstacleList.add(new Obstacle(240,380,7,this));

            //huo
            enemyList.add(new Enemy(550,380,true,4,this));
//激光
            enemyList.add(new Enemy(180,20,true,5,this,0,false));
            enemyList.add(new Enemy(330,20,true,5,this,800,true));
            enemyList.add(new Enemy(450,20,true,5,this,0,false));



        }


//        是否为第四关
        if(sort==4){
            //            绘制第四关的地面，上地面type=1，下地面type=2
            for(int i=0;i<27;i++){
                obstacleList.add(new Obstacle(i*30,420,1,this));
            }
            for(int j=0;j<=120;j+=30){
                for(int i=0;i<27;i++){
                    obstacleList.add(new Obstacle(i*30,570-j,2,this));
                }
            }
//            绘制第四个背景的A-O砖块
            int temp = 290;
            for (int i =390;i>=270;i-=30){
                for (int j =temp;j<=410;j+=30){
                    obstacleList.add(new Obstacle(j,i,7,this));
                }
                temp+=30;
            }
//            绘制第三个背景的P-R砖块
            temp=60;
            for (int i =390;i>=360;i-=30){
                for (int j=temp;j<=90;j+=30){
                    obstacleList.add(new Obstacle(j,i,7,this));
                }
                temp+=30;
            }
//            绘制旗杆
            gan = StaticValue.gan;
//            绘制城堡
            tower=StaticValue.tower;
//            添加旗子到旗杆上
            obstacleList.add(new Obstacle(515,220,8,this));

//            绘制第三关的蘑菇敌人
            enemyList.add(new Enemy(150,385,true,1,this));
            //第四关的激光
            enemyList.add(new Enemy(150,20,true,5,this,0,false));

            enemyList.add(new Enemy(240,20,true,5,this,0,false));
        }
}
    public BufferedImage getBgImage() {
        return bgImage;
    }

    public int getSort() {
        return sort;
    }

    public boolean  isFlag() {
        if(flag == 4){
            return true;
        }else {
            return false;
        }
    }
    public List<Obstacle> getObstacleList() {
        return obstacleList;
    }

    public BufferedImage getGan() {
        return gan;
    }

    public BufferedImage getTower() {
        return tower;
    }

    public boolean isReach() {
        return isReach;
    }

    public void setReach(boolean reach) {
        isReach = reach;
    }

    public boolean isBase() {
        return isBase;
    }

    public void setBase(boolean base) {
        isBase = base;
    }

    public List<Enemy> getEnemyList() {
        return enemyList;
    }
}
